//
//  THCPCDescriptionView.m
//  YJB
//
//  Created by 中电大维 on 2017/1/4.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "THCPCDescriptionView.h"

@implementation THCPCDescriptionView
{
    UIView *_textViewGround;
}
- (instancetype)init
{
    if (self = [super init]) {
        _textViewGround = [[UIView alloc] init];
        _textViewGround.backgroundColor = [UIColor colorWithHexString:@"eeeeee"];
        [self addSubview:_textViewGround];
        [self addSubview:self.desTextView];
        [self addSubview:self.iconButton];
        [self setSubviewFrame];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)addDescriptionImage:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(addDescriptionImage:)]) {
        [self.delegate addDescriptionImage:button];
    }
}

- (void)setSubviewFrame
{
    [_textViewGround mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(36);
    }];
    [_desTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.left.equalTo(self.mas_left).offset(12);
        make.right.equalTo(self.mas_right).offset(-12);
        make.height.mas_equalTo(36);
    }];
    [_iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_desTextView.mas_bottom).offset(15);
        make.left.equalTo(_desTextView.mas_left);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
        make.height.mas_equalTo(_iconButton.mas_width);
    }];

}

- (UITextView *)desTextView
{
    if (!_desTextView) {
        UITextView *textview = [[UITextView alloc] init];
        textview.font = FONT(15);
        textview.textColor = kUIColorFromRGB(0x333333);
        textview.textAlignment = NSTextAlignmentLeft;
        _desTextView = textview;
        _desTextView.backgroundColor = [UIColor clearColor];
    }
    return _desTextView;
}

- (UIButton *)iconButton
{
    if (!_iconButton) {
        UIButton *button = [[UIButton alloc] init];
        button.tag = 2;
        [button setImage:Image(@"task_placeholderImg_icon") forState:UIControlStateNormal];
        [button addTarget:self action:@selector(addDescriptionImage:) forControlEvents:UIControlEventTouchUpInside];
        _iconButton = button;
    }
    return _iconButton;
}

@end
